/**
 * Copyright 2018 墨斗鱼开源 http://www.mudouyu.com
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.modouyu.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置
 *
 * @author Mark mudouyu@aliyun.com
 * @since 3.0.0 2018-01-16
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
//        return new Docket(DocumentationType.SWAGGER_2)
//            .apiInfo(apiInfo())
//            .select()
//            //加了ApiOperation注解的类，生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
//            //包下的类，生成接口文档
//            //.apis(RequestHandlerSelectors.basePackage("com.modouyu.modules.job.controller"))
//            .paths(PathSelectors.any())
//            .build();


        return new Docket(DocumentationType.SWAGGER_2)
                .genericModelSubstitutes(DeferredResult.class)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(false)
                .pathMapping("/")
                .select()
                .build()
                .apiInfo(productApiInfo());


    }


    private ApiInfo productApiInfo() {

         return new ApiInfoBuilder()
                .title("墨斗鱼")
                 .description("墨斗鱼系统数据接口文档，快捷开发")
                 .version("1.0.0")
                 .termsOfServiceUrl("http://www.mudouyu.com")
                 .contact(new Contact("墨斗鱼","","mudouyu@aliyun.com"))
                 .build();

//        ApiInfoBuilder apiInfo = new ApiInfoBuilder("墨斗鱼系统数据接口文档",
//                "文档描述。。。",
//                "1.0.0",
//                "API TERMS URL",
//                "联系人邮箱",
//                "license",
//                "license url");
//        return apiInfo;
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("墨斗鱼开源")
                .description("renren-admin文档")
                .termsOfServiceUrl("http://www.mudouyu.com")
                .version("3.2.0")
                .build();
    }

}